Freeware assember ASxx.EXE Ver 1.03. 0001 ;DRVNO: ASK AdamNet Node (4 or 6): 0002 ;ETSKEW: ASK E&T (=1) or Orphanware Skew (=0): 0003 0004 0004 DRVNO EQU 4 0005 0001 ETSKEW EQU 1 0006 ; 0007 0000 P1DDR EQU 00H ;port 1 data direction register 0008 0001 P2DDR EQU 01H ;port 2 data direction register 0009 0002 P1DATA EQU 02H ;port 1 data register 0010 0003 P2DATA EQU 03H ;port 2 data register 0011 0005 P4DDR EQU 05H ;port 4 data direction register 0012 0008 TCSR EQU 08H ;timer control and status register 0013 0009 COUNTER EQU 09H ;counter register 0014 000b OUTCMP EQU 0BH ;output compare register 0015 0010 RMCR EQU 10H ;SCI rate and mode control register 0016 0011 SCICSR EQU 11H ;SCI Tx/Rx control and status register 0017 0012 SCIRXD EQU 12H ;SCI Rx data register 0018 0013 SCITXD EQU 13H ;SCI Tx data register 0019 0014 RAMCR EQU 14H ;RAM control register 0020 0080 CURMSG EQU 80H ;command message buffer (instructions for send/rcv) 0021 0085 LSTMSG EQU 85H ;last command buffer 0022 008a STRLEN EQU 8AH ;message length 0023 008c BLKLOC EQU 8CH ;where in memory to get/save message 0024 008e CHKSUM EQU 8EH ;calculated checksum 0025 008f MSTAT EQU 8FH ;status message buffer 0026 0093 CSTAT EQU 93H ;combined status 0027 0094 PSTAT EQU 94H ;primary status 0028 0095 SSTAT EQU 95H ;secondary status 0029 0096 L0096 EQU 96H 0030 0098 DEVNUM EQU 98H ;device node ID 0031 0099 CMDSTG EQU 99H ;command stage for multi-byte commands 0032 009e DATREQ EQU 9EH ;data requested flag 0033 009f RDWRT EQU 9FH ;read(=0BH)/write(=0CH) flag 0034 00a0 INTHAN EQU 0A0H ;address for interrupt handler 0035 00a2 DMADDR EQU 0A2H ;address for DMA with FDC 0036 00a4 STFDC EQU 0A4H ;FDC status 0037 00a5 REQTRK EQU 0A5H ;requested track 0038 00a6 REQSEC EQU 0A6H ;requested sector 0039 00a7 CURSEC EQU 0A7H ;current sector 0040 00a8 CURTRK EQU 0A8H ;current track 0041 00a9 SECRTY EQU 0A9H ;sector retries 0042 00aa RETRY EQU 0AAH ;block retries 0043 00ab DRVUSE EQU 0ABH ;has the drive been used? 0044 00ac MOTON EQU 0ACH ;is the motor on 0045 00e9 FMTTRK EQU 0E9H ;track being formatted 0046 00ea FMTSEC EQU 0EAH ;sector being formatted 0047 00eb FMTRTRY EQU 0EBH ;retries while formatting 0048 00ec SIDE EQU 0ECH ;side being formatted 0049 ; 0050 0012 SECHGH EQU 18 ;sectors per track in high density mode 0051 0009 SECLOW EQU SECHGH/2 ;sectors per track in low density mode 0052 0050 MAXTRK EQU 80 0053 ; 0054 0400 BLKWRT EQU 400H ;write to external memory 0055 0800 FDCSTAT EQU 800H ;FDC status register 0056 1400 BLKRD EQU 1400H ;read from external memory 0057 1800 FDCCMD EQU 1800H ;FDC command register 0058 3800 FDCTRK EQU 3800H ;FDC track register 0059 5800 FDCSEC EQU 5800H ;FDC sector register 0060 6c00 RDMA0 EQU 6C00H ;DMA read from FDC to 0 to 1FFH of ext. mem. 0061 6e00 RDMA1 EQU 6E00H ;DMA read from FDC to 200H to 3FFH of ext. mem. 0062 7800 FDCDAT EQU 7800H ;FDC data register 0063 7c00 WDMA0 EQU 7C00H ;DMA write to FDC from 0 to 1FFH of ext. mem. 0064 7e00 WDMA1 EQU 7E00H ;DMA write to FDC from 200H to 3FFH of ext. mem. 0065 ; 0066 ;AdamNet Messages where N = Node ID 0067 ; 0N - reset node 0068 ; 1N - request status 0069 ; 3N - clear 0070 ; 4N - receive 0071 ; 6N - send 0072 ;0DN - ready 0073 ; 0074 ; The disk drive code comprises two separate devices, the net handler 0075 ; and the disk handler. The net handler is only triggered when the 6803 0076 ; receives a byte over AdamNet. It interprets the AdamNet command, acts 0077 ; on the command (including sending and receiving blocks of data over the 0078 ; Net) and sets the appropriate flags and data blocks in memory. The 0079 ; disk handler is normally in control of the drive. It initializes the 0080 ; various flags and hardware and then loops, monitoring the data request 0081 ; flag. When it finds a data request, it reads or writes to the disk 0082 ; drive, depending upon the read/write flag. If the disk handler gets 0083 ; a request to write to block FACEH, it does a format. 0084 ; 0085 ;AdamNet procedure to write to disk: 0086 ; 1) Master node uses send command to send block specifications to disk drive. 0087 ; Block spec. is 5 bytes, 4 bytes block number (LSB ... MSB) and one byte 0088 ; device spec (0 = primary device, NZ = secondary device). The net 0089 ; handler puts all blocks less than 400H in message buffer. Blocks of 0090 ; 400H go in external memory. 0091 ; 2) Master node uses send command to send data block to disk. 0092 ; 3) Net handler sets data request and write flags and returns to disk 0093 ; handler. 0094 ; 4) Disk handler sees flags, reads the block specification and writes 0095 ; external memory to disk. 0096 ;AdamNet procedure to read from disk: 0097 ; 1) Master node uses send command to send block specifications to disk drive. 0098 ; 2) Master node uses receive command to tell disk drive to send data block. 0099 ; 3) Net handler sets data request and read flags and returns to disk 0100 ; handler. 0101 ; 4) Disk handler sees flags, reads the block specification and reads data 0102 ; from disk to external memory. 0103 ; 5) Meanwhile master node queries drive with RDY command. 0104 ; 6) Drive ACKs ready when disk handler has comleted task. 0105 ; 7) Master node then uses CLEAR command to tell net handler to send data. 0106 ; 8) Net handler now sends data in external memory 0107 ; 0108 ; 0109 f000 ORG 0F000H 0110 RESET: 0111 f000 0f SEI ;disable interrupts 0112 f001 8e 00 e8 LDS #$0E8 ;set stack pointer to E8 0113 f004 86 7a LDAA #$7A ;set port 1 data direction to 01111010 0114 f006 97 00 STAA P1DDR 0115 f008 86 ff LDAA #$0FF ;set port 4 data direction to 11111111 0116 f00a 97 05 STAA P4DDR 0117 f00c 86 15 LDAA #$15 ;set port 2 data direction to 00010101 0118 f00e 97 01 STAA P2DDR 0119 f010 86 0c LDAA #$0C ;set SCI rate & mode 62.5 kbaud, external clock 0120 f012 97 10 STAA RMCR 0121 f014 86 1b LDAA #$1B ;enable Rx, Tx, Wakeup 0122 f016 97 11 STAA SCICSR 0123 f018 86 ff LDAA #$0FF ;enable internal ram 0124 f01a 97 14 STAA RAMCR 0125 f01c 86 10 LDAA #$10 ;disable precomp;set double density, side 0, 0126 ;drive 1, motor off 00010000 0127 f01e 97 02 STAA P1DATA 0128 f020 ce 00 ff LDX #$0FF ;start clearing memory at 0FFH 0129 RESET1: 0130 f023 6f 00 CLR $0,X ;reset memory 0131 f025 09 DEX ;decrement pointer 0132 f026 8c 00 80 CPX #$80 ;is it 80H 0133 f029 24 f8 BCC RESET1 ;no, loop 0134 f02b 7a 00 89 DEC LSTMSG+4 ;set lstmsg+4 to 0FFH 0135 f02e 7c 00 ab INC DRVUSE ;set DRVUSE to 1 0136 f031 96 02 LDAA P1DATA ;read port 1 0137 f033 84 80 ANDA #$80 ;is switch on back set to drive ID 2 0138 f035 0c CLC ;clear carry 0139 f036 49 ROLA ;move bit 7 to bit 1 0140 f037 49 ROLA 0141 ; 0142 f038 8a 04 ORAA #DRVNO ;or in base drive ID 0143 ; 0144 f03a 97 98 STAA DEVNUM ;save it 0145 f03c bd f4 45 JSR HGHDEN 0146 f03f ce f0 47 LDX #MAIN ;MAIN is to be executed by interrupt 0147 f042 df a0 STX INTHAN ;save it 0148 f044 7e f2 ce JMP DSKRES 0149 MAIN: 0150 f047 ce 08 00 LDX #FDCSTAT ;read FDC status register 0151 f04a e6 00 LDAB $0,X 0152 f04c ce f0 47 LDX #MAIN ;set up interrupt handler 0153 f04f df a0 STX INTHAN 0154 f051 96 ac LDAA MOTON ;is MOTON 0 yet? 0155 f053 27 1a BEQ MAIN1 ;branch if so 0156 f055 86 40 LDAA #$40 ;is the output compare flag set 0157 f057 95 08 BITA TCSR 0158 f059 27 14 BEQ MAIN1 ;branch if not 0159 f05b 96 08 LDAA TCSR ;read TCSR 0160 f05d dc 09 LDD COUNTER ;set output compare to counter+3E80H 0161 f05f c3 3e 80 ADDD #$3E80 0162 f062 dd 0b STD OUTCMP 0163 f064 7a 00 ac DEC MOTON ;decrement MOTON 0164 f067 26 06 BNE MAIN1 ;non-zero, skip next 0165 f069 96 02 LDAA P1DATA 0166 f06b 84 9f ANDA #$9F ;turn motor off, select drive 1 10011111 0167 f06d 97 02 STAA P1DATA 0168 MAIN1: 0169 f06f 96 9e LDAA DATREQ ;is there a data request 0170 f071 26 48 BNE MAIN5 ;yes, skip next 0171 ; LDAB #$4 ;set secondary status to missing drive 0172 ; LDAB #$0E ;Use OE for Orphanware Skew 0173 f073 c6 0d LDAB #$0D ;Use OD for E&T Skew 0174 f075 96 02 LDAA P1DATA 0175 f077 84 08 ANDA #$8 0176 f079 27 02 BEQ MAIN2 0177 f07b c6 0f LDAB #$0F 0178 MAIN2: 0179 f07d d7 95 STAB SSTAT 0180 f07f d6 02 LDAB P1DATA ;test if disk in place 0181 f081 c5 01 BITB #$1 0182 f083 27 14 BEQ MAIN3 ;jump if it is 0183 f085 86 03 LDAA #$3 ;set primary status to missing media 0184 f087 97 94 STAA PSTAT 0185 f089 86 ff LDAA #$0FF ;invalidate last command 0186 f08b 97 89 STAA LSTMSG+4 0187 f08d 86 01 LDAA #$1 0188 f08f 97 ab STAA DRVUSE 0189 f091 96 02 LDAA P1DATA ;motor off, select drive 1 0190 f093 84 9f ANDA #$9F ;10011111 0191 f095 97 02 STAA P1DATA 0192 f097 20 1e BRA MAIN4 0193 MAIN3: 0194 f099 4f CLRA ;put 0 in A 0195 f09a d6 94 LDAB PSTAT ;primary status in B 0196 f09c c1 03 CMPB #$3 ;missing media or less 0197 f09e 25 17 BCS MAIN4 ;yes, skip next 0198 f0a0 c1 05 CMPB #$5 ;write protected 0199 f0a2 27 13 BEQ MAIN4 ;yes,skip next 0200 f0a4 36 PSHA ;save A and B 0201 f0a5 37 PSHB 0202 f0a6 96 02 LDAA P1DATA 0203 f0a8 8a 50 ORAA #$50 ;select side 0, turn motor on 1010000 0204 f0aa 97 02 STAA P1DATA 0205 f0ac bd f4 6c JSR RCOUNT ;restore counter 0206 f0af 33 PULB ;restore A & B 0207 f0b0 32 PULA 0208 f0b1 c1 05 CMPB #$5 ;write protected? 0209 f0b3 27 02 BEQ MAIN4 ;yes, skip next 0210 f0b5 97 94 STAA PSTAT ;save new primary status 0211 MAIN4: 0212 f0b7 96 9e LDAA DATREQ ;is there a data request 0213 f0b9 27 8c BEQ MAIN ;no, return to start of main loop 0214 MAIN5: 0215 f0bb 81 ff CMPA #$0FF ;is it reset drive request 0216 f0bd 26 03 BNE MAIN6 0217 f0bf 7e f1 42 JMP RESDRV ;yes, skip next 0218 MAIN6: 0219 f0c2 d6 84 LDAB CURMSG+4 ;is the primary device requested? 0220 f0c4 27 06 BEQ DODATA ;yes, skip next 0221 f0c6 7f 00 9e CLR DATREQ ;clear data request 0222 f0c9 7e f0 47 JMP MAIN ;loop some more 0223 DODATA: 0224 f0cc 0f SEI ;disable interrupts 0225 f0cd 96 02 LDAA P1DATA ;test if disk in place 0226 f0cf 85 01 BITA #$1 0227 f0d1 27 03 BEQ DODAT1 ;yes, skip next 0228 f0d3 7e f2 ce JMP DSKRES ;reset disk system 0229 DODAT1: 0230 f0d6 bd f4 52 JSR SELDRV ;select the drive 0231 f0d9 ce 00 b4 LDX #$0B4 ;wait count 0232 DODAT2: 0233 f0dc 09 DEX 0234 f0dd 26 fd BNE DODAT2 0235 f0df 7d 00 ab TST DRVUSE ;is this the first time the drive is used? 0236 f0e2 27 06 BEQ DODAT3 ;no, skip next 0237 f0e4 bd f3 20 JSR HOMDSK ;home the disk 0238 f0e7 7f 00 ab CLR DRVUSE ;set used flag 0239 DODAT3: 0240 f0ea 96 9f LDAA RDWRT ;test read/write flag 0241 f0ec 81 0c CMPA #$0C ;is it write? 0242 f0ee 26 3a BNE RDWRIT ;no, skip next 0243 f0f0 de 80 LDX CURMSG ;get requested block 0244 f0f2 8c 53 ca CPX #$53CA ;is it CA53 0245 f0f5 27 30 BEQ NOTFMT ;yes, skip next 0246 CHKFMT: 0247 f0f7 8c ce fa CPX #$0CEFA ;is it format = FACEH 0248 f0fa 26 05 BNE CHKFM1 ;no, skip next 0249 f0fc bd f4 d5 JSR FORMAT ;do the format 0250 f0ff 20 08 BRA CHKFM2 0251 CHKFM1: 0252 f101 8c cf fa CPX #$0CFFA ;is it low format = FACFH 0253 f104 26 24 BNE RDWRIT ;no, skip next 0254 f106 bd f4 d0 JSR LFORM ;do the format 0255 CHKFM2: 0256 f109 7f 00 a5 CLR REQTRK ;set requested track to 0 0257 f10c 86 ff LDAA #$0FF ;set all message bytes to 0FFH 0258 f10e 16 TAB 0259 f10f dd 85 STD LSTMSG 0260 f111 dd 87 STD LSTMSG+2 0261 f113 97 89 STAA LSTMSG+4 0262 f115 dd 80 STD CURMSG 0263 f117 dd 82 STD CURMSG+2 ;should be +2 ####### 0264 f119 97 84 STAA CURMSG+4 ; and +4 0265 f11b 96 e9 LDAA FMTTRK 0266 f11d 7f 00 e9 CLR FMTTRK 0267 f120 81 ff CMPA #$FF 0268 f122 27 03 BEQ NOTFMT 0269 f124 7e f2 c3 JMP MISBLK 0270 NOTFMT: 0271 f127 7e f2 ac JMP OKRDWR ;finish up with no error 0272 ; 0273 RDWRIT: 0274 f12a bd f2 dc JSR CLCTRK ;calculate track and sector 0275 f12d 24 03 BCC RDWRT1 ;if good, jump 0276 f12f 7e f2 c3 JMP MISBLK ;finish up with error 0277 RDWRT1: 0278 f132 96 9f LDAA RDWRT ;get read/write flag 0279 f134 81 0b CMPA #$0B ;is it read 0280 f136 27 13 BEQ RDBLK ;yes, do read 0281 f138 81 0c CMPA #$0C ;is it write 0282 f13a 27 03 BEQ RDWRT2 ;yes, do write 0283 f13c 7e f2 ac JMP OKRDWR ;else finish up no error 0284 RDWRT2: 0285 f13f 7e f2 07 JMP WRTBLK 0286 RESDRV: 0287 f142 bd f4 52 JSR SELDRV ;turn drive on and select it 0288 f145 bd f3 20 JSR HOMDSK ;home the disk 0289 f148 7e f0 00 JMP RESET ;reset entire drive system 0290 RDBLK: 0291 f14b 96 02 LDAA P1DATA ;is disk in place 0292 f14d 85 01 BITA #$1 0293 f14f 27 03 BEQ RDBLK1 ;yes, jump 0294 f151 7e f2 af JMP MISMED ;end with error 0295 RDBLK1: 0296 f154 bd f4 52 JSR SELDRV ;turn on drive 0297 f157 86 04 LDAA #$4 ;set retry count to 5 0298 f159 97 aa STAA RETRY 0299 RDBLK2: 0300 f15b cc 6c 00 LDD #RDMA0 ;DMA read to 1st half of memory 0301 f15e dd a2 STD DMADDR 0302 f160 96 a5 LDAA REQTRK ;seek to track 0303 f162 bd f3 44 JSR SKTRK 0304 f165 26 5f BNE RDERR ;if seek error 0305 f167 96 02 LDAA P1DATA 0306 f169 84 08 ANDA #$8 0307 f16b 27 2c BEQ RDBLK4 0308 f16d 96 a6 LDAA REQSEC ;get logical sector 0309 f16f bd f4 8d JSR HSECTRN ;translate to physical sector 0310 f172 bd f3 9b JSR RDHSEC ;read it 0311 f175 4d TSTA ;test error code 0312 f176 26 4e BNE RDERR ;jump if error 0313 f178 cc 6e 00 LDD #RDMA1 ;DMA read to 2nd half of memory 0314 f17b dd a2 STD DMADDR 0315 f17d 96 a6 LDAA REQSEC ;get logical sector 0316 f17f 4c INCA ;increase by 1 0317 f180 81 13 CMPA #SECHGH+1 ;past last sector on track 0318 f182 25 0d BCS RDBLK3 ;no, jump 0319 f184 96 a5 LDAA REQTRK ;get requested track 0320 f186 4c INCA ;increment to next track 0321 f187 bd f3 44 JSR SKTRK ;seek to it 0322 f18a 27 03 BEQ RDBL2A 0323 f18c 7e f2 c3 JMP MISBLK ;if seek error 0324 RDBL2A: 0325 f18f 86 01 LDAA #$1 ;must want first logical sector 0326 RDBLK3: 0327 f191 bd f4 8d JSR HSECTRN ;translate logical to physical 0328 f194 bd f3 9b JSR RDHSEC ;read sector 0329 f197 20 2a BRA RDBLK6 0330 RDBLK4: 0331 f199 96 a6 LDAA REQSEC ;get logical sector 0332 f19b bd f4 86 JSR LSECTRN ;translate to physical sector 0333 f19e bd f3 9f JSR RDLSEC ;read it 0334 f1a1 4d TSTA ;test error code 0335 f1a2 26 22 BNE RDERR ;jump if error 0336 f1a4 cc 6e 00 LDD #RDMA1 ;DMA read to 2nd half of memory 0337 f1a7 dd a2 STD DMADDR 0338 f1a9 96 a6 LDAA REQSEC ;get logical sector 0339 f1ab 4c INCA ;increase by 1 0340 f1ac 81 0a CMPA #SECLOW+1 ;past last sector on track 0341 f1ae 25 0d BCS RDBLK5 ;no, jump 0342 f1b0 96 a5 LDAA REQTRK ;get requested track 0343 f1b2 4c INCA ;increment to next track 0344 f1b3 bd f3 44 JSR SKTRK ;seek to it 0345 f1b6 27 03 BEQ RDBL4A 0346 f1b8 7e f2 c3 JMP MISBLK ;if seek error 0347 RDBL4A: 0348 f1bb 86 01 LDAA #$1 ;must want first logical sector 0349 RDBLK5: 0350 f1bd bd f4 86 JSR LSECTRN ;translate logical to physical 0351 f1c0 bd f3 9f JSR RDLSEC ;read sector 0352 RDBLK6: 0353 f1c3 4d TSTA ;test for error 0354 f1c4 27 32 BEQ OKRD ;everything is OK 0355 RDERR: 0356 f1c6 d6 aa LDAB RETRY ;get retries 0357 f1c8 5a DECB ;any left 0358 f1c9 d7 aa STAB RETRY ;save them 0359 f1cb 26 12 BNE RDRETRY ;do retry 0360 f1cd 4a DECA ;look at error 0361 f1ce 27 09 BEQ RDMBLK ;if 0, missing block 0362 f1d0 4a DECA 0363 f1d1 27 06 BEQ RDMBLK ;still missing block 0364 f1d3 4a DECA 0365 f1d4 27 06 BEQ RDCRC ;CRC error 0366 f1d6 7e f2 af JMP MISMED ;only thing left 0367 RDMBLK: 0368 f1d9 7e f2 c3 JMP MISBLK ;end up with missing block error code 0369 RDCRC: 0370 f1dc 7e f2 bf JMP CRC ;end up with crc error code 0371 RDRETRY: 0372 f1df c1 02 CMPB #$2 0373 f1e1 26 0f BNE RDRTR1 0374 f1e3 bd f4 3f JSR FLPDEN 0375 f1e6 bd f2 dc JSR CLCTRK 0376 f1e9 25 ee BCS RDMBLK 0377 f1eb 96 a5 LDAA REQTRK ;seek to track 0378 f1ed bd f3 44 JSR SKTRK 0379 f1f0 26 e7 BNE RDMBLK ;if seek error 0380 RDRTR1: 0381 f1f2 bd f3 20 JSR HOMDSK ;home the disk 0382 f1f5 7e f1 5b JMP RDBLK2 ;do retry 0383 OKRD: 0384 f1f8 dc 80 LDD CURMSG ;transfer current message to last message 0385 f1fa dd 85 STD LSTMSG 0386 f1fc dc 82 LDD CURMSG+2 0387 f1fe dd 87 STD LSTMSG+2 0388 f200 96 84 LDAA CURMSG+4 0389 f202 97 89 STAA LSTMSG+4 0390 f204 7e f2 ac JMP OKRDWR ;finish up, no error 0391 WRTBLK: 0392 f207 96 02 LDAA P1DATA ;is disk present 0393 f209 85 01 BITA #$1 0394 f20b 27 03 BEQ WRBLK1 0395 f20d 7e f2 af JMP MISMED ;no, exit with error 0396 WRBLK1: 0397 f210 86 ff LDAA #$0FF ;force new read 0398 f212 97 89 STAA LSTMSG+4 0399 f214 bd f4 52 JSR SELDRV ;select the drive 0400 f217 86 04 LDAA #$4 ;set retries 0401 f219 97 aa STAA RETRY 0402 WRBLK2: 0403 f21b cc 7c 00 LDD #WDMA0 ;DMA write from 1st half of memory 0404 f21e dd a2 STD DMADDR 0405 f220 96 a5 LDAA REQTRK 0406 f222 bd f3 44 JSR SKTRK ;seek to requested track 0407 f225 26 59 BNE WRTERR ;jump if error 0408 f227 96 02 LDAA P1DATA 0409 f229 84 08 ANDA #$8 0410 f22b 27 29 BEQ WRBLK4 0411 f22d 96 a6 LDAA REQSEC ;get logical sector 0412 f22f bd f4 8d JSR HSECTRN ;translate to physical sector 0413 f232 bd f3 ed JSR WRHSEC ;read it 0414 f235 4d TSTA 0415 f236 26 48 BNE WRTERR 0416 f238 cc 7e 00 LDD #WDMA1 ;DMA write from 2nd half of memory 0417 f23b dd a2 STD DMADDR 0418 f23d 96 a6 LDAA REQSEC ;get requested sector 0419 f23f 4c INCA ;go for next 0420 f240 81 13 CMPA #SECHGH+1 ;past end of track? 0421 f242 25 0a BCS WRBLK3 ;jump if not 0422 f244 96 a5 LDAA REQTRK ;seek to next track 0423 f246 4c INCA 0424 f247 bd f3 44 JSR SKTRK 0425 f24a 26 77 BNE MISBLK ;if seek error 0426 f24c 86 01 LDAA #$1 ;get first sector 0427 WRBLK3: 0428 f24e bd f4 8d JSR HSECTRN ;logical to physical translation 0429 f251 bd f3 ed JSR WRHSEC ;write sector 0430 f254 20 27 BRA WRBLK6 0431 WRBLK4: 0432 f256 96 a6 LDAA REQSEC ;get logical sector 0433 f258 bd f4 86 JSR LSECTRN ;translate to physical sector 0434 f25b bd f3 f1 JSR WRLSEC ;read it 0435 f25e 4d TSTA 0436 f25f 26 1f BNE WRTERR 0437 f261 cc 7e 00 LDD #WDMA1 ;DMA write from 2nd half of memory 0438 f264 dd a2 STD DMADDR 0439 f266 96 a6 LDAA REQSEC ;get requested sector 0440 f268 4c INCA ;go for next 0441 f269 81 0a CMPA #SECLOW+1 ;past end of track? 0442 f26b 25 0a BCS WRBLK5 ;jump if not 0443 f26d 96 a5 LDAA REQTRK ;seek to next track 0444 f26f 4c INCA 0445 f270 bd f3 44 JSR SKTRK 0446 f273 26 4e BNE MISBLK ;if seek error 0447 f275 86 01 LDAA #$1 ;get first sector 0448 WRBLK5: 0449 f277 bd f4 86 JSR LSECTRN ;logical to physical translation 0450 f27a bd f3 f1 JSR WRLSEC ;write sector 0451 WRBLK6: 0452 f27d 4d TSTA 0453 f27e 27 2c BEQ OKRDWR 0454 WRTERR: 0455 f280 d6 aa LDAB RETRY ;get retry count 0456 f282 5a DECB ;any left? 0457 f283 d7 aa STAB RETRY ;save retries 0458 f285 26 0c BNE WRRETRY ;do retry 0459 f287 81 04 CMPA #$4 ;look at error code 0460 f289 27 24 BEQ MISMED ;must be missing media 0461 f28b 81 03 CMPA #$3 0462 f28d 26 34 BNE MISBLK ;must be missing block 0463 f28f 86 05 LDAA #$5 ;must be write-protected 0464 f291 20 32 BRA DSKDN 0465 WRRETRY: 0466 f293 c1 02 CMPB #$2 0467 f295 26 0f BNE WRRTR1 0468 f297 bd f4 3f JSR FLPDEN 0469 f29a bd f2 dc JSR CLCTRK 0470 f29d 25 24 BCS MISBLK 0471 f29f 96 a5 LDAA REQTRK ;seek to track 0472 f2a1 bd f3 44 JSR SKTRK 0473 f2a4 26 1d BNE MISBLK ;if seek error 0474 WRRTR1: 0475 f2a6 bd f3 20 JSR HOMDSK ;home disk 0476 f2a9 7e f2 1b JMP WRBLK2 ;go back for retry 0477 OKRDWR: 0478 f2ac 4f CLRA ;no error so clear A 0479 f2ad 20 16 BRA DSKDN 0480 MISMED: 0481 f2af dc 80 LDD CURMSG ;transfer current message to last message 0482 f2b1 dd 85 STD LSTMSG 0483 f2b3 dc 82 LDD CURMSG+2 0484 f2b5 dd 87 STD LSTMSG+2 0485 f2b7 96 84 LDAA CURMSG+4 0486 f2b9 97 89 STAA LSTMSG+4 0487 f2bb 86 03 LDAA #$3 ;status = missing media 0488 f2bd 20 06 BRA DSKDN 0489 CRC: 0490 f2bf 86 01 LDAA #$1 ;status = CRC error 0491 f2c1 20 02 BRA DSKDN 0492 MISBLK: 0493 f2c3 86 02 LDAA #$2 ;status = missing block error 0494 DSKDN: 0495 f2c5 97 94 STAA PSTAT 0496 ; BRA DSKDN1 0497 ; 0498 ; STAA SSTAT ;unused code for secondary device 0499 DSKDN1: 0500 f2c7 7f 00 9e CLR DATREQ 0501 f2ca 86 1b LDAA #$1B ;enable Tx, Rx, Wakeup 0502 f2cc 97 11 STAA SCICSR 0503 DSKRES: 0504 f2ce bd f4 6c JSR RCOUNT 0505 f2d1 86 1b LDAA #$1B ;enable Tx, Rx, Wakeup 0506 f2d3 97 11 STAA SCICSR 0507 f2d5 4f CLRA 0508 f2d6 97 99 STAA CMDSTG ;reset command stage 0509 f2d8 0e CLI ;enable interrupts 0510 f2d9 7e f0 47 JMP MAIN ;wait loop 0511 ; 0512 CLCTRK: 0513 f2dc 37 PSHB ;save accumulators 0514 f2dd 36 PSHA 0515 f2de 7f 00 a5 CLR REQTRK ;initialize REQTRK to -1 0516 f2e1 7a 00 a5 DEC REQTRK 0517 f2e4 96 02 LDAA P1DATA 0518 f2e6 8a 70 ORAA #$70 ;select drive, motor on, side 0 01110000 0519 f2e8 97 02 STAA P1DATA 0520 f2ea 84 08 ANDA #$8 0521 f2ec 27 12 BEQ CLCTR2 0522 f2ee d6 80 LDAB CURMSG ;get requested block in A & B 0523 f2f0 96 81 LDAA CURMSG+1 0524 f2f2 05 LSLD ;multiply by 2 to go from 1K to 512 byte blocks 0525 CLCTR1: 0526 f2f3 83 00 12 SUBD #SECHGH ;divide sector requested by 8 0527 f2f6 7c 00 a5 INC REQTRK ;keeping count in REQTRK 0528 f2f9 24 f8 BCC CLCTR1 ;until overflow 0529 f2fb c3 00 13 ADDD #SECHGH+1 ;add back overflow + 1 (sectors start at 1 not 0) 0530 f2fe 20 10 BRA CLCTR4 0531 CLCTR2: 0532 f300 d6 80 LDAB CURMSG ;get requested block in A & B 0533 f302 96 81 LDAA CURMSG+1 0534 f304 05 LSLD ;multiply by 2 to go from 1K to 512 byte blocks 0535 CLCTR3: 0536 f305 83 00 09 SUBD #SECLOW ;divide sector requested by 8 0537 f308 7c 00 a5 INC REQTRK ;keeping count in REQTRK 0538 f30b 24 f8 BCC CLCTR3 ;until overflow 0539 f30d c3 00 0a ADDD #SECLOW+1 ;add back overflow + 1 (sectors start at 1 not 0) 0540 CLCTR4: 0541 f310 96 a5 LDAA REQTRK ;check if requested track > MAXTRK 0542 f312 81 a0 CMPA #MAXTRK*2 0543 f314 24 03 BCC CLCTR5 ;yes, skip next 0544 f316 d7 a6 STAB REQSEC ;save calculated sector 0545 f318 0d SEC ;set carry 0546 CLCTR5: 0547 f319 07 TPA ;transfer condition code register to A 0548 f31a 88 01 EORA #$1 ;reverse what was the carry 0549 f31c 06 TAP ;transfer A to condition code register 0550 f31d 32 PULA ;restore A & B 0551 f31e 33 PULB 0552 f31f 39 RTS 0553 HOMDSK: 0554 f320 96 02 LDAA P1DATA ;check if disk in place 0555 f322 85 01 BITA #$1 0556 f324 26 15 BNE HOMDK2 ;if not finish up 0557 f326 ce f3 3b LDX #HOMDK2 ;set up interrupt handler 0558 f329 df a0 STX INTHAN 0559 f32b ce 18 00 LDX #FDCCMD ;prepare to write to FDC command register 0560 f32e 86 05 LDAA #$5 ;restore command with verify and 6ms step rate 0561 f330 a7 00 STAA $0,X ;do it 0562 f332 86 01 LDAA #$1 0563 HOMDK1: 0564 f334 95 02 BITA P1DATA ;keep testing for disk in place 0565 f336 27 fc BEQ HOMDK1 0566 f338 bd f4 7a JSR FORINT ;oops, disk gone so force interrupt 0567 HOMDK2: 0568 f33b ce 38 00 LDX #FDCTRK ;prepare to write to FDC track register 0569 f33e 4f CLRA 0570 f33f a7 00 STAA $0,X ;put a 0 there 0571 f341 97 a8 STAA CURTRK ;and in current track 0572 f343 39 RTS 0573 SKTRK: 0574 f344 d6 02 LDAB P1DATA ;is disk in plce 0575 f346 c5 01 BITB #$1 0576 f348 26 4e BNE DSKERR ;no, branch to error 0577 f34a 81 a0 CMPA #MAXTRK*2 ;is track greater than 80 0578 f34c 24 4a BCC DSKERR ;yes, branch to error 0579 f34e 44 LSRA ;divide by 2 0580 f34f 24 08 BCC SKTRK1 ;if odd, skip next 0581 ;comment out next 3 lines if using 2797 side select line 0582 f351 d6 02 LDAB P1DATA ;select side 1 0583 f353 c4 ef ANDB #$0EF ;11101111 0584 f355 d7 02 STAB P1DATA 0585 ; LDAB #$2 ;for read/write sector ******* 0586 ; STAB SIDE ;******** 0587 f357 20 06 BRA SKTRK2 ;skip next 0588 SKTRK1: 0589 ;comment out next 3 lines if using 2797 side select line 0590 f359 d6 02 LDAB P1DATA ;select side 0 0591 f35b ca 10 ORAB #$10 ;00010000 0592 f35d d7 02 STAB P1DATA 0593 ; CLR SIDE ;******* 0594 SKTRK2: 0595 f35f ce f3 7d LDX #SKTRK4 ;set up interrupt handler 0596 f362 df a0 STX INTHAN 0597 f364 ce 78 00 LDX #FDCDAT ;prepare to write to FDC data register 0598 f367 a7 00 STAA $0,X ;put track there 0599 f369 97 a8 STAA CURTRK ;save in current track 0600 f36b ce 18 00 LDX #FDCCMD ;prepare to write to FDC command register 0601 f36e c6 15 LDAB #$15 ;seek commmand, with verify and 6ms step rate 0602 f370 e7 00 STAB $0,X ;do it 0603 f372 86 01 LDAA #$1 0604 SKTRK3: 0605 f374 95 02 BITA P1DATA ;keep testing disk in place 0606 f376 27 fc BEQ SKTRK3 ;until FDC interrupts out 0607 f378 bd f4 7a JSR FORINT ;oops, disk out so force interrupt 0608 f37b 20 1b BRA DSKERR ;and send error 0609 SKTRK4: 0610 f37d 96 a8 LDAA CURTRK ;get current track 0611 f37f ce 38 00 LDX #FDCTRK ;get ready to write to FDC track register 0612 f382 a7 00 STAA $0,X ;put track in register 0613 f384 81 12 CMPA #$12 ;is it track 12 or less 0614 f386 24 08 BCC SKTRK5 ;no, skip next 0615 f388 96 02 LDAA P1DATA ;disable write precompensation 0616 f38a 84 fd ANDA #$0FD ;11111101 0617 f38c 97 02 STAA P1DATA 0618 f38e 20 06 BRA SKTRK6 ;skip next 0619 SKTRK5: 0620 f390 96 02 LDAA P1DATA ;enable write precompensation 0621 f392 8a 02 ORAA #$2 ;00000010 0622 f394 97 02 STAA P1DATA 0623 SKTRK6: 0624 f396 4f CLRA ;finish up with no error 0625 f397 39 RTS 0626 DSKERR: 0627 f398 86 01 LDAA #$1 0628 f39a 39 RTS 0629 RDHSEC: 0630 f39b 81 13 CMPA #SECHGH+1 ;past end of track? 0631 f39d 20 02 BRA RDSEC0 0632 RDLSEC: 0633 f39f 81 0a CMPA #SECLOW+1 0634 RDSEC0: 0635 f3a1 24 2f BCC RDSEC3 0636 RDSEC: 0637 f3a3 97 a7 STAA CURSEC ;save sector 0638 f3a5 86 02 LDAA #$2 ;set 4 retries, 2 for each density 0639 f3a7 97 a9 STAA SECRTY 0640 RDSEC1: 0641 f3a9 ce 58 00 LDX #FDCSEC ;get ready to set FDC sector register 0642 f3ac 96 a7 LDAA CURSEC ;with sector 0643 f3ae a7 00 STAA $0,X ;do it 0644 f3b0 ce f3 d6 LDX #RDSEC4 ;set up interrupt handler 0645 f3b3 df a0 STX INTHAN 0646 f3b5 ce 18 00 LDX #FDCCMD ;get ready to set FDC command register 0647 f3b8 86 84 LDAA #$84 ;read sector command with no side compare ***** 0648 ;and 30ms delay 0649 ; LDAA #$8C ;read sector command ********* 0650 ; ORAA SIDE ;set side select ********* 0651 f3ba a7 00 STAA $0,X ;do it 0652 f3bc de a2 LDX DMADDR point to memory to save data 0653 RDSEC2: 0654 f3be d6 02 LDAB P1DATA ;check if disk in place and FDC DRQ 0655 f3c0 c5 05 BITB #$5 ;00000101 0656 f3c2 27 fa BEQ RDSEC2 ;loop until check positive 0657 f3c4 a6 00 LDAA $0,X ;get data 0658 f3c6 08 INX ;next memory address 0659 f3c7 c5 01 BITB #$1 ;disk in place? 0660 f3c9 27 f3 BEQ RDSEC2 ;yes go for more data 0661 f3cb bd f4 7a JSR FORINT ;force interrupt 0662 f3ce 86 04 LDAA #$4 ;missing media error 0663 f3d0 20 1a BRA RDSEC7 ;exit 0664 RDSEC3: 0665 f3d2 86 01 LDAA #$1 ;missing block error 0666 f3d4 20 16 BRA RDSEC7 ;exit 0667 RDSEC4: 0668 f3d6 d6 a4 LDAB STFDC ;get floppy disk status 0669 f3d8 86 03 LDAA #$3 ;assume error 3, CRC 0670 f3da c5 0c BITB #$0C ;test status 0671 f3dc 27 07 BEQ RDSEC6 ;no, its not 0672 RDSEC5: 0673 f3de 7a 00 a9 DEC SECRTY ;decrement retries 0674 f3e1 27 09 BEQ RDSEC7 ;exit if all gone 0675 f3e3 20 c4 BRA RDSEC1 ;do a retry 0676 RDSEC6: 0677 f3e5 86 02 LDAA #$2 ;assume error 2 0678 f3e7 c5 10 BITB #$10 ;test for sector not found 0679 f3e9 26 f3 BNE RDSEC5 ;if not, no error so exit 0680 f3eb 4f CLRA ;no error 0681 RDSEC7: 0682 f3ec 39 RTS ;exit 0683 WRHSEC: 0684 f3ed 81 13 CMPA #SECHGH+1 ;past end of track 0685 f3ef 20 02 BRA WRTSC0 0686 WRLSEC: 0687 f3f1 81 0a CMPA #SECLOW+1 ;past end of track 0688 WRTSC0: 0689 f3f3 24 2f BCC WRTSC3 ;exit missing block 0690 WRTSEC: 0691 f3f5 97 a7 STAA CURSEC ;save in current sector 0692 f3f7 86 02 LDAA #$2 ;set retries 0693 f3f9 97 a9 STAA SECRTY 0694 WRTSC1: 0695 f3fb 96 a7 LDAA CURSEC ;get current sector 0696 f3fd ce 58 00 LDX #FDCSEC ;prepare to write to FDC sector register 0697 f400 a7 00 STAA $0,X ;do it 0698 f402 ce f4 28 LDX #WRTSC4 ;set up interrupt handler 0699 f405 df a0 STX INTHAN 0700 f407 86 a4 LDAA #$0A4 ;FDC write command ****** 0701 ; LDAA #$0AC ;FDC write command ********* 0702 ; ORAA SIDE ;set side select ********* 0703 f409 ce 18 00 LDX #FDCCMD ;prepare to write to FDC command register 0704 f40c a7 00 STAA $0,X ;do it 0705 f40e de a2 LDX DMADDR 0706 WRTSC2: 0707 f410 d6 02 LDAB P1DATA ;check if disk in place and FDC DRQ 0708 f412 c5 05 BITB #$5 ;00000101 0709 f414 27 fa BEQ WRTSC2 ;loop until check positive 0710 f416 a6 00 LDAA $0,X ;get data 0711 f418 08 INX ;next memory address 0712 f419 c5 01 BITB #$1 ;disk still in place 0713 f41b 27 f3 BEQ WRTSC2 ;yes go for more data 0714 f41d bd f4 7a JSR FORINT ;force interrupt 0715 f420 86 04 LDAA #$4 ;missing media error 0716 f422 20 1a BRA WRTSC7 ;exit 0717 WRTSC3: 0718 f424 86 01 LDAA #$1 ;missing block error 0719 f426 20 16 BRA WRTSC7 ;exit 0720 WRTSC4: 0721 f428 d6 a4 LDAB STFDC ;get floppy disk status 0722 f42a 86 02 LDAA #$2 ;assume missing block error 0723 f42c c5 14 BITB #$14 ;test status 0724 f42e 27 07 BEQ WRTSC6 ;not missing block 0725 WRTSC5: 0726 f430 7a 00 a9 DEC SECRTY ;decrement retry count 0727 f433 27 09 BEQ WRTSC7 ;do another 0728 f435 20 c4 BRA WRTSC1 ;else exit 0729 WRTSC6: 0730 f437 86 03 LDAA #$3 ;assume write protect error 0731 f439 c5 40 BITB #$40 ;test status 0732 f43b 26 01 BNE WRTSC7 ;got write protect error 0733 f43d 4f CLRA ;everything OK 0734 WRTSC7: 0735 f43e 39 RTS ;exit 0736 0737 FLPDEN: 0738 f43f 96 02 LDAA P1DATA ;ready to test if in high density mode 0739 f441 84 08 ANDA #$8 ;test it 0740 f443 26 06 BNE LOWDEN ;in high so set low 0741 HGHDEN: 0742 f445 96 02 LDAA P1DATA ;get port 1 data 0743 f447 8a 08 ORAA #$8 ;turn on high density bit 0744 f449 20 04 BRA SETDEN 0745 LOWDEN: 0746 f44b 96 02 LDAA P1DATA ;get port 1 data 0747 f44d 84 f7 ANDA #$0F7 ;turn off high density bit 0748 SETDEN: 0749 f44f 97 02 STAA P1DATA ;set it 0750 f451 39 RTS 0751 SELDRV: 0752 f452 36 PSHA ;save A & IX 0753 f453 3c PSHX 0754 f454 96 02 LDAA P1DATA ;test if drive is selected 0755 f456 85 20 BITA #$20 ;00100000 0756 f458 26 0f BNE SELDR3 ;yes, finish up 0757 f45a 8a 70 ORAA #$70 ;turn motor on, select drive and side 0 01110000 0758 f45c 97 02 STAA P1DATA 0759 f45e 86 02 LDAA #$2 ;counter for outer wait loop 0760 SELDR1: 0761 f460 ce 9c 40 LDX #$9C40 ;counter for inner wait loop 0762 SELDR2: 0763 f463 09 DEX 0764 f464 26 fd BNE SELDR2 ;do inner loop 0765 f466 4a DECA 0766 f467 26 f7 BNE SELDR1 ;do outer loop 0767 SELDR3: 0768 f469 38 PULX ;restore IX and A 0769 f46a 32 PULA 0770 f46b 39 RTS 0771 ; 0772 RCOUNT: 0773 f46c 96 08 LDAA TCSR ;set output compare to counter + 3E80H 0774 f46e dc 09 LDD COUNTER 0775 f470 c3 3e 80 ADDD #$3E80 0776 f473 dd 0b STD OUTCMP 0777 f475 86 fa LDAA #$0FA ;put 0FAH in MOTON 0778 f477 97 ac STAA MOTON 0779 f479 39 RTS 0780 ; 0781 ; LDAA #$3 ;unused code 0782 ; STAA PSTAT 0783 ; 0784 FORINT: 0785 f47a ce 18 00 LDX #FDCCMD ;get ready to write to FDC command register 0786 f47d 86 d0 LDAA #$0D0 ;force interrupt cmd - terminate with 0787 ;no interrupt 0788 f47f a7 00 STAA $0,X ;do it 0789 f481 86 01 LDAA #$1 ;set drive not used 0790 f483 97 ab STAA DRVUSE 0791 f485 39 RTS 0792 ; 0793 LSECTRN: 0794 f486 3c PSHX ;save IX & B 0795 f487 37 PSHB 0796 f488 ce f4 9a LDX #SKEW9 ;point to 9 sector skew table 0797 f48b 20 05 BRA SECTRN 0798 HSECTRN: 0799 f48d 3c PSHX ;save IX & B 0800 f48e 37 PSHB 0801 f48f ce f4 a3 LDX #SKEW18 ;point to 18 sector skew table 0802 SECTRN: 0803 f492 16 TAB ;transfer A to B 0804 f493 5a DECB ;dec B 0805 SCTRN1: 0806 f494 3a ABX ;add offset 0807 f495 a6 00 LDAA $0,X ;get physical sector 0808 f497 33 PULB ;restore IX & B 0809 f498 38 PULX 0810 f499 39 RTS 0811 SKEW9: 0812 ; 0813 ; Double density: 0814 ; To enable Orphanware sector translation (3:1 Skew), comment 0815 ; out the second line; to enable E&T sector translation (4:1 0816 ; skew), comment out the first line below) 0817 ; DB 1,4,7,2,5,8,3,6,9 ;Orphanware Sector Translation 0818 f49a 01 05 09 04 08 03 DB 1,5,9,4,8,3,7,2,6 :E&T Sector Translation 07 02 06 0819 ; 0820 ; High density: always 4:1 (E&T) 0821 SKEW18: 0822 f4a3 01 05 09 0d 11 03 DB 1,5,9,13,17,3,7,11,15,2,6,10,14,18,4,8,12,16 07 0b 0f 02 06 0a 0e 12 04 08 0c 10 0823 ; 0824 FDCINT: 0825 f4b5 ce 08 00 LDX #FDCSTAT ;read FDC status register 0826 f4b8 a6 00 LDAA $0,X 0827 f4ba 30 TSX ;transfer stack pointer to X 0828 f4bb c6 05 LDAB #$5 ;increase by 5 0829 f4bd 3a ABX 0830 f4be dc a0 LDD INTHAN ;get interrupt handler in DA 0831 f4c0 a7 00 STAA $0,X ;put in stack 0832 f4c2 08 INX 0833 f4c3 e7 00 STAB $0,X 0834 f4c5 ce 08 00 LDX #FDCSTAT ;prepare to read FDC status register 0835 FDCIN2: 0836 f4c8 21 fe BRN FDCIN2 ;delay 0837 f4ca a6 00 LDAA $0,X ;read status 0838 f4cc 97 a4 STAA STFDC 0839 f4ce 3b RTI 0840 f4cf 3b RTI 0841 LFORM: 0842 f4d0 bd f4 4b JSR LOWDEN 0843 f4d3 20 03 BRA FORM1 0844 FORMAT: 0845 f4d5 bd f4 45 JSR HGHDEN ;set high density mode 0846 FORM1: 0847 f4d8 7f 00 ec CLR SIDE ;clear side 2 flag 0848 f4db 96 02 LDAA P1DATA ;is disk in place? 0849 f4dd 85 01 BITA #$1 0850 f4df 27 05 BEQ FMT0 ;yes, go on formatting 0851 f4e1 86 10 LDAA #$10 ;turn motor and drive off, select side 0 0852 f4e3 97 02 STAA P1DATA 0853 f4e5 39 RTS 0854 FMT0: 0855 f4e6 8a 10 ORAA #$10 0856 f4e8 97 02 STAA P1DATA 0857 FMT1: 0858 f4ea bd f3 20 JSR HOMDSK ;home disk ****** useless should comment out 0859 f4ed 86 4f LDAA #MAXTRK-1 ;set track to format 0860 f4ef 97 e9 STAA FMTTRK 0861 FMT2: 0862 f4f1 ce f5 06 LDX #FMT4 ;set up interrupt handler 0863 f4f4 df a0 STX INTHAN 0864 f4f6 ce 78 00 LDX #FDCDAT ;prepare to write to FDC data register 0865 f4f9 96 e9 LDAA FMTTRK ;get track 0866 f4fb a7 00 STAA $0,X ;put in data register 0867 f4fd ce 18 00 LDX #FDCCMD ;prepare to write to FDC command register 0868 f500 86 11 LDAA #$11 ;seek command, no verify, 6ms step 0869 f502 a7 00 STAA $0,X ;issue command 0870 FMT3: 0871 f504 20 fe BRA FMT3 ;wait for seek to end 0872 FMT4: 0873 f506 86 0a LDAA #$0A ;set format retries to 10 0874 f508 97 eb STAA FMTRTRY 0875 FMT5: 0876 f50a 96 02 LDAA P1DATA ;turn motor on, and select drive 1, leave side 0877 ; ANDA #$70 ;01110000 0878 f50c 8a 60 ORAA #$60 ;01100000 0879 f50e 97 02 STAA P1DATA 0880 f510 86 01 LDAA #$1 ;set format sector to 1 0881 f512 97 ea STAA FMTSEC 0882 f514 ce f6 2e LDX #FMT37 ;set up pointer to interrupt handler 0883 f517 df a0 STX INTHAN 0884 f519 96 e9 LDAA FMTTRK ;get current track 0885 f51b 81 12 CMPA #$12 ;is it less than 12 0886 f51d 24 06 BCC FMT6 ;no, jump 0887 f51f 96 02 LDAA P1DATA ;disable write precompensation 0888 f521 84 fd ANDA #$0FD ;11111101 0889 f523 20 04 BRA FMT7 0890 FMT6: 0891 f525 96 02 LDAA P1DATA ;enable write precompensation 0892 f527 8a 02 ORAA #$2 ;00000010 0893 FMT7: 0894 f529 97 02 STAA P1DATA 0895 f52b 86 f0 LDAA #$0F0 ;FDC write track command in A 0896 f52d ce 18 00 LDX #FDCCMD ;prepare to write to FDC command register 0897 f530 a7 00 STAA $0,X ;do it 0898 f532 ce 78 00 LDX #FDCDAT ;prepare to write to FDC data register 0899 f535 c6 64 LDAB #$64 ;write 64H/100D bytes of data 0900 FMT8: 0901 f537 86 04 LDAA #$4 ;prepare to test DRQ 0902 FMT9: 0903 f539 95 02 BITA P1DATA ;test it 0904 f53b 27 fc BEQ FMT9 ;loop til set 0905 f53d 86 4e LDAA #$4E ;write 4EH 0906 f53f a7 00 STAA $0,X 0907 f541 5a DECB ;decrement count 0908 f542 26 f3 BNE FMT8 ;loop till count gone 0909 FMT10: 0910 f544 c6 0c LDAB #$0C ;now writing 0CH/12D bytes 0911 FMT11: 0912 f546 86 04 LDAA #$4 ;prepare to test DRQ 0913 FMT12: 0914 f548 95 02 BITA P1DATA ;test it 0915 f54a 27 fc BEQ FMT12 ;loop till set 0916 f54c 4f CLRA ;write 0 0917 f54d a7 00 STAA $0,X ;do it 0918 f54f 5a DECB ;decrement count 0919 f550 26 f4 BNE FMT11 ;loop till exhausted 0920 f552 c6 03 LDAB #$3 ;now write 3 bytes 0921 FMT13: 0922 f554 86 04 LDAA #$4 ;prepare to test DRQ 0923 FMT14: 0924 f556 95 02 BITA P1DATA ;test it 0925 f558 27 fc BEQ FMT14 ;loop till set 0926 f55a 86 f5 LDAA #$0F5 ;write 0F5H (3 bytes of A1) 0927 f55c a7 00 STAA $0,X ;do it 0928 f55e 5a DECB ;decrement count 0929 f55f 26 f3 BNE FMT13 ;loop till exhausted 0930 f561 86 04 LDAA #$4 ;prepare to test DRQ 0931 FMT15: 0932 f563 95 02 BITA P1DATA ;test it 0933 f565 27 fc BEQ FMT15 ;loop till set 0934 f567 86 fe LDAA #$0FE ;write 0FEH (index mark) 0935 f569 a7 00 STAA $0,X ;do it 0936 f56b 86 04 LDAA #$4 ;prepare to test DRQ 0937 FMT16: 0938 f56d 95 02 BITA P1DATA ;test it 0939 f56f 27 fc BEQ FMT16 ;loop till set 0940 f571 96 e9 LDAA FMTTRK ;get track number 0941 f573 a7 00 STAA $0,X ;wwrite to FDC 0942 f575 86 04 LDAA #$4 ;prepare to test DRQ 0943 FMT17: 0944 f577 95 02 BITA P1DATA ;test it 0945 f579 27 fc BEQ FMT17 ;loop till set 0946 f57b 96 ec LDAA SIDE ;get side 0947 ; LSRA ;convert to 0&1 instead of 0&2 ****** 0948 f57d a7 00 STAA $0,X ;write it 0949 f57f 86 04 LDAA #$4 ;prepare to test DRQ 0950 FMT18: 0951 f581 95 02 BITA P1DATA ;test it 0952 f583 27 fc BEQ FMT18 ;loop till set 0953 f585 96 ea LDAA FMTSEC ;get sector number 0954 f587 a7 00 STAA $0,X ;write it 0955 f589 4c INCA ;increment sector number 0956 f58a 97 ea STAA FMTSEC ;save it 0957 f58c 86 04 LDAA #$4 ;prepare to test DRQ 0958 FMT19: 0959 f58e 95 02 BITA P1DATA ;test it 0960 f590 27 fc BEQ FMT19 ;wait till set 0961 f592 86 02 LDAA #$2 ;write sector length byte (2 = 512 bytes) 0962 f594 a7 00 STAA $0,X ;write it 0963 f596 86 04 LDAA #$4 ;prepare to test DRQ 0964 FMT20: 0965 f598 95 02 BITA P1DATA ;test it 0966 f59a 27 fc BEQ FMT20 ;loop till set 0967 f59c 86 f7 LDAA #$0F7 ;write 0F7H (writes CRC) 0968 f59e a7 00 STAA $0,X ;write it 0969 f5a0 c6 16 LDAB #$16 ;load count with 16H/22D 0970 FMT21: 0971 f5a2 86 04 LDAA #$4 ;prepare to test DRQ 0972 FMT22: 0973 f5a4 95 02 BITA P1DATA ;test it 0974 f5a6 27 fc BEQ FMT22 ;loop till set 0975 f5a8 86 4e LDAA #$4E ;write 4EH 0976 f5aa a7 00 STAA $0,X ;write it 0977 f5ac 5a DECB ;decrement count 0978 f5ad 26 f3 BNE FMT21 ;loop till exhausted 0979 f5af c6 0c LDAB #$0C ;load count with 0CH/12D 0980 FMT23: 0981 f5b1 86 04 LDAA #$4 ;get ready to test DRQ 0982 FMT24: 0983 f5b3 95 02 BITA P1DATA ;test it 0984 f5b5 27 fc BEQ FMT24 ;loop till done 0985 f5b7 4f CLRA ;write 0 0986 f5b8 a7 00 STAA $0,X ;write it 0987 f5ba 5a DECB ;decrement count 0988 f5bb 26 f4 BNE FMT23 ;loop till exhausted 0989 f5bd c6 03 LDAB #$3 ;count = 3 0990 FMT25: 0991 f5bf 86 04 LDAA #$4 ;prepare to test DRQ 0992 FMT26: 0993 f5c1 95 02 BITA P1DATA ;test it 0994 f5c3 27 fc BEQ FMT26 ;loop till set 0995 f5c5 86 f5 LDAA #$0F5 ;write 0F5H (3 bytes of A1) 0996 f5c7 a7 00 STAA $0,X ;write it 0997 f5c9 5a DECB ;decrement count 0998 f5ca 26 f3 BNE FMT25 ;loop till exhausted 0999 f5cc 86 04 LDAA #$4 ;prepare to test DRQ 1000 FMT27: 1001 f5ce 95 02 BITA P1DATA ;test it 1002 f5d0 27 fc BEQ FMT27 ;loop till set 1003 f5d2 86 fb LDAA #$0FB ;write 0FBH (address mark) 1004 f5d4 a7 00 STAA $0,X ;write it 1005 f5d6 5f CLRB ;clear B (count = 256) 1006 FMT28: 1007 f5d7 86 04 LDAA #$4 ;prepare to test DRQ 1008 FMT29: 1009 f5d9 95 02 BITA P1DATA ;test it 1010 f5db 27 fc BEQ FMT29 ;loop till set 1011 f5dd 86 e5 LDAA #$0E5 ;write 0E5H 1012 f5df a7 00 STAA $0,X ;write it 1013 f5e1 5a DECB ;decrement count 1014 f5e2 26 f3 BNE FMT28 ;loop till exhausted 1015 FMT30: 1016 f5e4 86 04 LDAA #$4 ;prepare to test DRQ 1017 FMT31: 1018 f5e6 95 02 BITA P1DATA ;test it 1019 f5e8 27 fc BEQ FMT31 ;loop till set 1020 f5ea 86 e5 LDAA #$0E5 ;writing 0E5H 1021 f5ec a7 00 STAA $0,X ;write it 1022 f5ee 5a DECB ;decrement count 1023 f5ef 26 f3 BNE FMT30 ;loop till exhausted 1024 f5f1 86 04 LDAA #$4 ;prepare to test DRQ 1025 FMT32: 1026 f5f3 95 02 BITA P1DATA ;test it 1027 f5f5 27 fc BEQ FMT32 ;loop till set 1028 f5f7 86 f7 LDAA #$0F7 ;writing 0F7H (CRC) 1029 f5f9 a7 00 STAA $0,X ;write it 1030 f5fb c6 64 LDAB #$64 ;count = 64H/100D 1031 FMT33: 1032 f5fd 86 04 LDAA #$4 ;prepare to test DRQ 1033 FMT34: 1034 f5ff 95 02 BITA P1DATA ;test it 1035 f601 27 fc BEQ FMT34 ;loop till set 1036 f603 86 4e LDAA #$4E ;writing 4EH 1037 f605 a7 00 STAA $0,X ;write it 1038 f607 5a DECB ;decrement count 1039 f608 26 f3 BNE FMT33 ;loop till exhausted 1040 f60a 96 02 LDAA P1DATA 1041 f60c 84 08 ANDA #$8 1042 f60e 27 09 BEQ FMT34A 1043 f610 96 ea LDAA FMTSEC 1044 f612 81 13 CMPA #SECHGH+1 1045 f614 27 0c BEQ FMT35 1046 f616 7e f5 44 JMP FMT10 ;no, go back and write another sector 1047 FMT34A: 1048 f619 96 ea LDAA FMTSEC 1049 f61b 81 0a CMPA #SECLOW+1 1050 f61d 27 03 BEQ FMT35 1051 f61f 7e f5 44 JMP FMT10 ;no, go back and write another sector 1052 FMT35: 1053 f622 c6 4e LDAB #$4E ;get ready to fill track with 4EH 1054 FMT36: 1055 f624 96 02 LDAA P1DATA ;test DRQ 1056 f626 85 04 BITA #$4 ;is it set 1057 f628 27 fa BEQ FMT36 ;no, loop till set 1058 f62a e7 00 STAB $0,X ;write byte 1059 f62c 20 f6 BRA FMT36 ;loop till FDC interrupts out 1060 FMT37: ;format continues here once one track is formatted 1061 f62e ce 08 00 LDX #FDCSTAT ;read FDC status register 1062 f631 e6 00 LDAB $0,X 1063 f633 c5 01 BITB #$1 ;test busy 1064 f635 26 f7 BNE FMT37 ;wait till not busy 1065 f637 96 a4 LDAA STFDC ;get status after command completed 1066 f639 85 04 BITA #$4 ;test for lost data 1067 f63b 27 12 BEQ FMT38 ;jump if none 1068 FMT37A: 1069 f63d 7a 00 eb DEC FMTRTRY ;decrement retries 1070 f640 27 0c BEQ FMT37C ;go on if exhausted 1071 f642 96 eb LDAA FMTRTRY 1072 f644 81 05 CMPA #$5 1073 f646 26 03 BNE FMT37B 1074 f648 bd f4 3f JSR FLPDEN 1075 FMT37B: 1076 f64b 7e f5 0a JMP FMT5 ;re-format track 1077 FMT37C: 1078 f64e 39 RTS 1079 FMT38: 1080 f64f 96 e9 LDAA FMTTRK 1081 f651 81 4f CMPA #MAXTRK-1 1082 f653 26 11 BNE FMT38A 1083 f655 96 ec LDAA SIDE 1084 f657 26 0d BNE FMT38A 1085 f659 cc 6c 00 LDD #RDMA0 ;DMA read to 1st half of memory 1086 f65c dd a2 STD DMADDR 1087 f65e 86 03 LDAA #$3 1088 f660 bd f3 a3 JSR RDSEC 1089 f663 4d TSTA 1090 f664 26 d7 BNE FMT37A 1091 FMT38A: 1092 ; LDDA BLKRD ;read first byte of data block 1093 ; CMPA #$1 ;is it 1 1094 ; BEQ FMT39 ;if it is, do not format side 1 1095 f666 96 ec LDAA SIDE ;get the side 1096 f668 26 0b BNE FMT39 ;jump if we just did side 1 1097 f66a 7c 00 ec INC SIDE ;increment side ******* 1098 ; LDAA #$2 ;******** 1099 ; STAA SIDE ;******** 1100 ;comment out next 3 lines if using 2797 side select line 1101 f66d 96 02 LDAA P1DATA ;select side 1 1102 f66f 84 ef ANDA #$0EF ;11101111 1103 f671 97 02 STAA P1DATA 1104 f673 20 0c BRA FMT40 ;skip next 1105 FMT39: 1106 f675 7f 00 ec CLR SIDE ;select side 0 1107 ;comment out next 3 lines if using 2797 side select line 1108 f678 96 02 LDAA P1DATA 1109 f67a 8a 10 ORAA #$10 ;00010000 1110 f67c 97 02 STAA P1DATA 1111 f67e 7a 00 e9 DEC FMTTRK ;decrement track to format 1112 FMT40: 1113 f681 96 e9 LDAA FMTTRK ;check if formatted all tracks 1114 f683 81 ff CMPA #$0FF 1115 f685 27 03 BEQ FMT41 ;yes finish up 1116 f687 7e f4 f1 JMP FMT2 ;no, go back and format new track 1117 FMT41: 1118 f68a 7e f3 20 JMP HOMDSK ;home the disk (it already is) 1119 ; 1120 f800 ORG 0F800H 1121 ; 1122 f800 17 TBA 1123 ; 1124 SCIINT: 1125 f801 7d 00 9e TST DATREQ ;is there an active data request 1126 f804 26 26 BNE SCINT3 ;if none, finish up, ignoring Net 1127 f806 bd f9 f5 JSR RDSCI ;read byte from SCI 1128 f809 25 2b BCS SCINT4 ;jump if good read (and good net address) 1129 f80b 28 1f BVC SCINT3 ;if address bad, finish up, ignoring Net 1130 ;must be bad read, so NACK it 1131 f80d 86 02 LDAA #$2 ;enable Tx interrupt 1132 f80f 97 11 STAA SCICSR 1133 SCINT1: 1134 f811 ce 00 0e LDX #$0E ;set wait count 1135 f814 86 08 LDAA #$8 ;get ready to test bit 3 1136 SCINT2: 1137 f816 95 03 BITA P2DATA ;is bit 3 of port 2 data set by SCI 1138 f818 27 f7 BEQ SCINT1 ;no, loop until it's set 1139 f81a 09 DEX ;make sure it stays set long enough 1140 f81b 26 f9 BNE SCINT2 ;by looping until IX = 0 1141 f81d 86 1b LDAA #$1B ;enable Rx, RxI, Wakeup 1142 f81f 97 11 STAA SCICSR 1143 f821 7d 00 99 TST CMDSTG ;are we in the middle of a command 1144 f824 27 06 BEQ SCINT3 ;no, just reset SCI 1145 f826 4f CLRA ;clear command stage flag 1146 f827 97 99 STAA CMDSTG 1147 f829 7e f8 98 JMP NACK ;send NACK 1148 SCINT3: 1149 f82c c6 1b LDAB #$1B ;enable Rx, RxI, Wakeup 1150 f82e d7 11 STAB SCICSR 1151 f830 4f CLRA ;clear command stage flag 1152 f831 97 99 STAA CMDSTG 1153 f833 7e f9 d4 JMP SCIEND ;reset SCI 1154 SCINT4: 1155 f836 d6 99 LDAB CMDSTG ;get the command stage flag in B 1156 f838 58 ASLB ;multiply by 2 1157 f839 ce f8 41 LDX #TBL1 ;point to command jump table 1158 f83c 3a ABX ;add offset in B 1159 f83d ee 00 LDX $0,X ;get address from table 1160 JMPIX: 1161 f83f 6e 00 JMP $0,X ;jump to address 1162 TBL1: 1163 f841 f8 4d DW STAGE0 1164 f843 f9 2a DW STAGE1 1165 f845 f9 33 DW STAGE2 1166 f847 f9 58 DW STAGE3 1167 f849 f9 5f DW STAGE4 1168 f84b f9 79 DW STAGE5 1169 STAGE0: 1170 f84d 84 f0 ANDA #$0F0 ;mask off lower nibble 1171 f84f 81 00 CMPA #$0 ;is it NetReset 1172 f851 26 07 BNE NOTRST ;no, check other commands 1173 ; SEC ;set carry 1174 ; JSR SETREQ 1175 f853 86 ff LDAA #$0FF ;put FF in DATREQ 1176 f855 97 9e STAA DATREQ 1177 f857 7e f9 d4 JMP SCIEND ;reset SCI 1178 NOTRST: 1179 f85a 81 10 CMPA #$10 ;is it status request? 1180 f85c 27 62 BEQ STATUS ;yes, jump 1181 f85e 81 30 CMPA #$30 ;is it clear 1182 f860 26 03 BNE NOTCLR ;no, jump 1183 f862 7e f8 e8 JMP CLEAR 1184 NOTCLR: 1185 f865 81 40 CMPA #$40 ;is it Rx 1186 f867 26 1d BNE NOTRX ;no, jump 1187 f869 ce 00 05 LDX #$5 ;counter to test 5 bytes 1188 RX1: 1189 f86c a6 7f LDAA $7F,X ;compare location 7F+X 1190 f86e a1 84 CMPA $84,X ;to location 84+X 1191 f870 26 05 BNE RX2 ;jump if different 1192 f872 09 DEX ;check counter 1193 f873 26 f7 BNE RX1 ;loop if more bytes to check 1194 f875 20 35 BRA ACK ;all the same to send ACK 1195 RX2: 1196 f877 86 0b LDAA #$0B 1197 ; CLC 1198 ; JSR SETREQ 1199 f879 97 9f STAA RDWRT ;put's 0BH in RDWRT to force a read 1200 f87b 86 aa LDAA #$0AA ;put AA in DATREQ 1201 f87d 97 9e STAA DATREQ 1202 f87f 86 0b LDAA #$0B ;disable receive interrupt 1203 f881 97 11 STAA SCICSR 1204 f883 7e f9 d4 JMP SCIEND 1205 NOTRX: 1206 f886 81 60 CMPA #$60 ;is it send 1207 f888 26 07 BNE NOTSND ;no, jump 1208 f88a 86 01 LDAA #$1 ;now stage 0 1209 f88c 97 99 STAA CMDSTG ;so set it 1210 f88e 7e f9 d4 JMP SCIEND ;reset SCi 1211 NOTSND: 1212 f891 81 d0 CMPA #$0D0 ;is it RDY 1213 f893 27 17 BEQ ACK ;yes, send ACK 1214 f895 7e f9 d4 JMP SCIEND ;else reset SCI (ignore command) 1215 NACK: 1216 f898 86 c0 LDAA #$0C0 ;NACK in upper nibble of A 1217 f89a 9a 98 ORAA DEVNUM ;node ID in lower nibble of A 1218 f89c bd fa 13 JSR TXBYTE ;send it 1219 f89f 25 08 BCS NACK1 ;if bad send 1220 f8a1 bd fa 2b JSR RXBYTE ;get response 1221 f8a4 25 03 BCS NACK1 ;if bad receive 1222 f8a6 7e f9 d4 JMP SCIEND ;reset SCI 1223 NACK1: 1224 f8a9 7e f9 e4 JMP RETI ;return from interrupt 1225 ACK: 1226 f8ac 86 90 LDAA #$90 ;ACK in upper nibble of A 1227 f8ae 9a 98 ORAA DEVNUM ;node ID in lower nibble 1228 f8b0 bd fa 13 JSR TXBYTE ;send it 1229 f8b3 25 08 BCS ACK1 ;if bad send 1230 f8b5 bd fa 2b JSR RXBYTE ;get response 1231 f8b8 25 03 BCS ACK1 ;if bad receive 1232 f8ba 7e f9 d4 JMP SCIEND ;reset SCI 1233 ACK1: 1234 f8bd 7e f9 e4 JMP RETI ;return from interrupt 1235 STATUS: 1236 f8c0 fc f9 f0 LDD TBL2 ;load double accumulator with 8000H 1237 ;(status + MSB of msg len) 1238 f8c3 9a 98 ORAA DEVNUM ;put device number in lower nibble of A (=80) 1239 f8c5 dd 8f STD MSTAT ;save in buffer for status message 1240 f8c7 fc f9 f2 LDD TBL3 ;load double accumulator with 401H 1241 f8ca dd 91 STD MSTAT+2 ;put in 91 and 92 1242 f8cc bd f9 e5 JSR GETSTAT ;put double stat in 93 1243 f8cf ce 00 8f LDX #MSTAT ;point to string to send 1244 f8d2 cc 00 05 LDD #$5 ;load double accumulator with string length 1245 f8d5 dd 8a STD STRLEN ;save string length 1246 f8d7 86 80 LDAA #$80 ;initialize checksum 1247 f8d9 9a 98 ORAA DEVNUM 1248 f8db 97 8e STAA CHKSUM 1249 f8dd bd f9 b4 JSR TXSTR ;send response 1250 f8e0 25 03 BCS STAT1 ;if error 1251 ; LDAA #$1 1252 ; STAA L0096 ;put 1 if ???? flag - not used anywhere else 1253 f8e2 7e f9 d4 JMP SCIEND ;reset SCI 1254 STAT1: 1255 f8e5 7e f9 e4 JMP RETI ;jump to RTI 1256 CLEAR: 1257 f8e8 7d 00 84 TST CURMSG+4 ;was the last command for primary device 1258 f8eb 27 04 BEQ CLR1 ;yes, skip next 1259 f8ed 96 95 LDAA SSTAT ;so load secondary device status 1260 f8ef 20 02 BRA CLR2 ;skip next 1261 CLR1: 1262 f8f1 96 94 LDAA PSTAT ;get primary device status 1263 CLR2: 1264 f8f3 81 03 CMPA #$3 ;test status 1265 f8f5 24 0a BCC CLR3 ;if 3 or greater, jump 1266 f8f7 ce 14 00 LDX #BLKRD ;get ready to read external memory 1267 f8fa cc 04 00 LDD #$0400 ;400H to send 1268 f8fd dd 8a STD STRLEN ;so set message length 1269 f8ff 20 0b BRA CLR4 ;skip next 1270 CLR3: 1271 f901 bd f9 e5 JSR GETSTAT ;put combined status message in CSTAT 1272 f904 ce 00 93 LDX #CSTAT ;point to CSTAT 1273 f907 cc 00 01 LDD #$1 ;message length = 1 1274 f90a dd 8a STD STRLEN 1275 CLR4: 1276 f90c bd f9 9a JSR SNDMSG ;send message (Block or error) 1277 f90f 25 16 BCS CLR8 ;if error 1278 f911 7d 00 84 TST CURMSG+4 ;was last for primary device 1279 f914 27 04 BEQ CLR5 ;yes, skip next 1280 f916 96 95 LDAA SSTAT ;get secondary status 1281 f918 20 02 BRA CLR6 ;skip next 1282 CLR5: 1283 f91a 96 94 LDAA PSTAT ;get primary status 1284 CLR6: 1285 f91c 81 01 CMPA #$1 ;test status 1286 f91e 26 04 BNE CLR7 ;if not 1, jump 1287 f920 86 ff LDAA #$0FF ;set external memory contents bad 1288 f922 97 89 STAA LSTMSG+4 1289 CLR7: 1290 f924 7e f9 d4 JMP SCIEND ;exit 1291 CLR8: 1292 f927 7e f9 e4 JMP RETI ;do simple RTI 1293 STAGE1: 1294 ;A = MSB of message length 1295 f92a 97 8a STAA STRLEN ;save MSB of message length 1296 f92c 86 02 LDAA #$2 ;activate stage 2 1297 f92e 97 99 STAA CMDSTG 1298 f930 7e f9 d4 JMP SCIEND ;reset SCI 1299 STAGE2: 1300 ;A = LSB of message length 1301 f933 97 8b STAA STRLEN+1 ;save LSB of message length 1302 f935 81 05 CMPA #$5 ;is it 5? 1303 f937 26 04 BNE STAG21 ;no, it must be 400H 1304 f939 96 8a LDAA STRLEN ;get MSB of message length 1305 f93b 27 0c BEQ STAG22 ;if it's 0, ie 0005, jump 1306 STAG21: 1307 f93d 86 03 LDAA #$3 ;activate stage 3 1308 f93f 97 99 STAA CMDSTG 1309 f941 cc 04 00 LDD #BLKWRT ;block to go at 400H 1310 f944 dd 8c STD BLKLOC 1311 f946 7e f9 d4 JMP SCIEND ;reset SCI 1312 STAG22: 1313 f949 86 04 LDAA #$4 ;activate stage 4 1314 f94b 97 99 STAA CMDSTG 1315 f94d cc 00 80 LDD #$80 ;block to go at 80H 1316 f950 dd 8c STD BLKLOC 1317 f952 7f 00 8e CLR CHKSUM ;clear the checksum 1318 f955 7e f9 d4 JMP SCIEND ;reset SCI 1319 STAGE3: 1320 ;A = first byte of message 1321 f958 c6 04 LDAB #$4 ;activate stage 4 1322 f95a d7 99 STAB CMDSTG 1323 f95c 7f 00 8e CLR CHKSUM ;clear checksum 1324 STAGE4: 1325 ;A = message byte 1326 f95f de 8c LDX BLKLOC ;get memory location to save message 1327 f961 a7 00 STAA $0,X ;save there 1328 f963 08 INX ;increment pointer 1329 f964 df 8c STX BLKLOC ;save it 1330 f966 98 8e EORA CHKSUM ;calculate checksum 1331 f968 97 8e STAA CHKSUM ;save it 1332 f96a dc 8a LDD STRLEN ;get message length 1333 f96c 83 00 01 SUBD #$1 ;decrement it 1334 f96f dd 8a STD STRLEN ;save it 1335 f971 26 61 BNE SCIEND ;reset SCI if not done 1336 f973 86 05 LDAA #$5 ;else activate stage 5 1337 f975 97 99 STAA CMDSTG 1338 f977 20 5b BRA SCIEND ;and reset SCI 1339 STAGE5: 1340 ;A = message checksum 1341 f979 c6 00 LDAB #$0 ;reset commmand stage to 0 1342 f97b d7 99 STAB CMDSTG 1343 f97d 91 8e CMPA CHKSUM ;check against calculated checksum 1344 f97f 27 07 BEQ STAG51 ;if they're the same jump 1345 f981 86 02 LDAA #$2 ;else set primary status to 2 1346 f983 97 94 STAA PSTAT 1347 f985 7e f8 98 JMP NACK ;and send NACK 1348 STAG51: 1349 f988 de 8c LDX BLKLOC ;check if loaded at 80H or 400H 1350 f98a 8c 01 00 CPX #$0100 1351 f98d 25 08 BCS STAG52 ;carry set if 80H, so just send ACK 1352 f98f 86 0c LDAA #$0C ;set data write 1353 f991 97 9f STAA RDWRT 1354 f993 86 aa LDAA #$0AA ;data request flag 1355 f995 97 9e STAA DATREQ 1356 STAG52: 1357 f997 7e f8 ac JMP ACK ;send ACK 1358 SNDMSG: 1359 f99a 86 b0 LDAA #$0B0 ;Minor node send 1360 f99c 9a 98 ORAA DEVNUM ;or in Node ID 1361 f99e bd fa 13 JSR TXBYTE ;send it 1362 f9a1 25 30 BCS TXSTR1 ;if bad send 1363 f9a3 96 8a LDAA STRLEN ;get message length MSB 1364 f9a5 bd fa 13 JSR TXBYTE ;send it 1365 f9a8 25 29 BCS TXSTR1 ;if bad send 1366 f9aa 96 8b LDAA STRLEN+1 ;get message length LSB 1367 f9ac bd fa 13 JSR TXBYTE ;send it 1368 f9af 25 22 BCS TXSTR1 ;if bad send 1369 f9b1 7f 00 8e CLR CHKSUM ;clear checksum and fall through to send message 1370 TXSTR: 1371 f9b4 a6 00 LDAA $0,X ;get byte pointed to by IX 1372 f9b6 bd fa 13 JSR TXBYTE ;send it 1373 f9b9 25 18 BCS TXSTR1 ;jump if error 1374 f9bb 98 8e EORA CHKSUM ;generate checksum 1375 f9bd 97 8e STAA CHKSUM ;save it 1376 f9bf 08 INX ;increment pointer 1377 f9c0 dc 8a LDD STRLEN ;load DA with string length 1378 f9c2 83 00 01 SUBD #$1 ;decrement it 1379 f9c5 dd 8a STD STRLEN ;save string length 1380 f9c7 26 eb BNE TXSTR ;send more if leength > 0 1381 f9c9 96 8e LDAA CHKSUM ;get checksum 1382 f9cb bd fa 13 JSR TXBYTE ;send it 1383 f9ce 25 03 BCS TXSTR1 ;if error 1384 f9d0 bd fa 2b JSR RXBYTE ;get response 1385 TXSTR1: 1386 f9d3 39 RTS 1387 SCIEND: 1388 f9d4 7d 00 9e TST DATREQ ;test SCI status flag 1389 f9d7 27 0b BEQ RETI ;if it's 0 exit, SCI routine 1390 f9d9 86 0a LDAA #$0A ;enable Rx & Tx, but disable interrupts 1391 f9db 97 11 STAA SCICSR 1392 f9dd 96 11 LDAA SCICSR ;read status to reset 1393 f9df 96 12 LDAA SCIRXD ;read receive to reset 1394 f9e1 bd fa 2b JSR RXBYTE ;read byte from Net 1395 RETI: 1396 f9e4 3b RTI ;return from SCI interrupt 1397 GETSTAT: 1398 f9e5 96 95 LDAA SSTAT ;get contents of 95 in A 1399 f9e7 48 ASLA ;put in upper nibble 1400 f9e8 48 ASLA 1401 f9e9 48 ASLA 1402 f9ea 48 ASLA 1403 f9eb 9a 94 ORAA PSTAT ;put 94 in lower nibble 1404 f9ed 97 93 STAA CSTAT ;save in 93 1405 f9ef 39 RTS 1406 TBL2: 1407 f9f0 80 00 DW $8000 1408 TBL3: 1409 f9f2 04 01 DW $401 1410 f9f4 00 DB $0 1411 RDSCI: 1412 f9f5 0d SEC ;set carry flag 1413 f9f6 d6 11 LDAB SCICSR ;get SCI status in B 1414 f9f8 96 12 LDAA SCIRXD ;read SCI data 1415 f9fa c4 40 ANDB #$40 ;check for read errors, carry not affected 1416 f9fc 27 03 BEQ RDSCI1 ;branch if no error 1417 f9fe 0c CLC ;clear the carry 1418 f9ff 0b SEV ;set overflow 1419 fa00 39 RTS 1420 RDSCI1: 1421 fa01 d6 99 LDAB CMDSTG ;check if in middle of a command 1422 fa03 26 0c BNE RDSCI3 ;branch if so 1423 fa05 16 TAB ;transfer Node ID to B 1424 fa06 84 0f ANDA #$0F ;look at lower nibble of ID 1425 fa08 91 98 CMPA DEVNUM ;is it us 1426 fa0a 26 04 BNE RDSCI2 ;jump if not 1427 fa0c 17 TBA ;put byte back in A 1428 fa0d 0d SEC ;set the carry 1429 fa0e 20 01 BRA RDSCI3 ;clear next 1430 RDSCI2: 1431 fa10 0c CLC ;clear carry 1432 RDSCI3: 1433 fa11 0a CLV ;clear overflow 1434 fa12 39 RTS 1435 TXBYTE: 1436 fa13 3c PSHX ;save IX 1437 fa14 ce 00 16 LDX #$16 ;store count for timeout 1438 TXBYT1: 1439 fa17 09 DEX ;decrement count 1440 fa18 27 0b BEQ TXBYT2 ;timeout if count exhausted 1441 fa1a d6 11 LDAB SCICSR ;get SCI status 1442 fa1c c4 20 ANDB #$20 ;is Tx register full 1443 fa1e 27 f7 BEQ TXBYT1 ;wait if it is 1444 fa20 97 13 STAA SCITXD ;put byte in Tx register (send it) 1445 fa22 0c CLC ;clear the carry 1446 fa23 20 04 BRA TXBYT3 ;exit 1447 TXBYT2: 1448 fa25 bd fa 49 JSR SCIRES ;reset SCI 1449 fa28 0d SEC ;set the carry 1450 TXBYT3: 1451 fa29 38 PULX ;restore IX 1452 fa2a 39 RTS 1453 RXBYTE: 1454 fa2b 3c PSHX ;save IX 1455 fa2c ce 00 22 LDX #$22 ;count for timeout 1456 RXBYT1: 1457 fa2f 09 DEX ;decrement count 1458 fa30 27 13 BEQ RXBYT3 ;timeout if count exhausted 1459 fa32 d6 11 LDAB SCICSR ;get SCI status 1460 fa34 c4 20 ANDB #$20 ;check if last byte transmitted yet 1461 fa36 27 f7 BEQ RXBYT1 ;wait until it is 1462 fa38 d6 12 LDAB SCIRXD ;read Rx data 1463 RXBYT2: 1464 fa3a 09 DEX ;decrement counter 1465 fa3b 27 08 BEQ RXBYT3 ;if timed out 1466 fa3d d6 11 LDAB SCICSR ;read SCI status 1467 fa3f 2a f9 BPL RXBYT2 ;loop if bit 7 is not set 1468 fa41 d6 12 LDAB SCIRXD ;read byte 1469 fa43 38 PULX ;restore IX 1470 fa44 39 RTS 1471 RXBYT3: 1472 fa45 8d 02 BSR SCIRES ;reset SCI 1473 fa47 38 PULX ;restore IX 1474 fa48 39 RTS 1475 SCIRES: 1476 fa49 d6 11 LDAB SCICSR ;read SCI status 1477 fa4b d6 12 LDAB SCIRXD ;clear any received data 1478 fa4d c6 1b LDAB #$1B ;enable Rx, Tx, Wakeup 1479 fa4f d7 11 STAB SCICSR 1480 fa51 c6 00 LDAB #$0 ;reset command stage to 0 1481 fa53 d7 99 STAB CMDSTG 1482 fa55 39 RTS 1483 ; 1484 fff0 ORG 0FFF0H 1485 ; 1486 ;RETI: 1487 ; RTI ;return from interrupt 1488 fff0 f8 01 DW SCIINT ;IRQ2/SCI (RDRF,ORFE,TDRE) 1489 fff2 f9 e4 DW RETI ;IRQ2/Timer overflow 1490 fff4 f9 e4 DW RETI ;IRQ2/Timer output compare 1491 fff6 f9 e4 DW RETI ;IRQ2/Timer input capture 1492 fff8 f9 e4 DW RETI ;IRQ1 interrupt (IRQ1 - IS3) 1493 fffa f9 e4 DW RETI ;software interrupt (SWI) 1494 fffc f4 b5 DW FDCINT ;Non-maskable Interrupt 1495 fffe f0 00 DW RESET ;reset 1496 END Number of errors 0